<?php

declare(strict_types=1);

namespace App\Controller;

use App\Service\AdvancePayService;
use App\Service\PayService;
use Hyperf\Di\Annotation\Inject;
use Yansongda\Pay\Gateways\Alipay;
use Yansongda\Pay\Gateways\Wechat;

/**
 * 第三方支付回调
 * Class NotifyController
 * @package App\Controller
 */
class NotifyController extends AbstractController
{

    /**
     * @Inject
     * @var PayService
     */
    private $payService;

    /**
     * @Inject
     * @var AdvancePayService
     */
    private $advancePay;

    /**
     * 订单支付回调
     * @return bool|int|Alipay|Wechat
     */
    public function payNotify()
    {
        $out_trade_no = $this->request->post('out_trade_no', '');
        // 获取支付类型
        $pay_type = $this->advancePay->getPayTypeByOuterSN($out_trade_no);
        if (empty($pay_type)) {
            echo "支付记录不存在";
            return -1;
        }
        // 处理回调
        return $this->payService->notify($pay_type);

    }
}